//
//  MyView.m
//  CAReoplitorLayer
//
//  Created by 张云飞 on 2017/1/3.
//  Copyright © 2017年 张云飞. All rights reserved.
//

#import "MyView.h"

@implementation MyView
{
    CAShapeLayer *layer;
    CABasicAnimation *basicAnimation;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self draw];
    }
    return self;
}
- (void)draw
{
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 10, 10)];
    layer = [CAShapeLayer layer];
    layer.frame = CGRectMake(10, 45, 10, 10);

    layer.path = path.CGPath;
    layer.fillColor = [UIColor redColor].CGColor;
    
    basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
    basicAnimation.duration = 5;
    basicAnimation.repeatCount = INT_MAX;
    basicAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DTranslate(CATransform3DIdentity, 0, 0, 0)];
    basicAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DTranslate(CATransform3DIdentity, 35, 35, 0)];
    [layer addAnimation:basicAnimation forKey:@"animation"];

    
    CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
    replicatorLayer.frame = CGRectMake(0, 0, 100, 100);
    replicatorLayer.instanceCount = 4;
    replicatorLayer.instanceTransform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1);
    [replicatorLayer addSublayer:layer];
    [self.layer addSublayer:replicatorLayer];
    
    
    
}
- (void)star
{
    layer.speed = 1.0f;
}
- (void)stop
{
    layer.speed = 0;
    
}
@end
